import 'package:blog_flutter/controller/MenuController.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class SliderMenuWidget extends StatelessWidget {

  final MenuController _menuController = Get.put(MenuController());

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: Container(
        color: Colors.black,
        child: Obx(() {
          return buildListView();
        })
      ),
    );
  }
  
  Widget buildListView() {
    return ListView(
      children: [
        DrawerHeader(child: Text("我的博客", style: TextStyle(color: Colors.red, fontWeight: FontWeight.w600, fontSize: 22),)),
        ...List.generate(_menuController.menuList.length, (index) => SilderMenuItemWidget(_menuController.menuList[index],
            _menuController.currentSelectIndex == index, () {_menuController.updateSelectIndex(index);}))
      ],
    );
  }


}




class SilderMenuItemWidget extends StatelessWidget{

  final String title;
  final bool isSelected;
  final Function onTap;

  SilderMenuItemWidget(this.title, this.isSelected, this.onTap);

  @override
  Widget build(BuildContext context) {
    return ListTile(
      onTap: onTap,
      selected: isSelected,
      selectedTileColor: Colors.red,
      contentPadding: EdgeInsets.only(left: 20),
      title: Text(
        title,
        style: TextStyle(
          color: Colors.white,
          fontWeight: FontWeight.w500,
        ),
      ),
    );
  }

}
